<?php
session_start(); // on relaye la session 
if(isset($_SESSION["is_registered"]) && $_SESSION["is_registered"] == "registered"){
		$enregistrer = $_SESSION["is_registered"];
}else{
	header("location:../../../menu.php"); // redirection en cas d'echec
}
 require_once('../../../Connections/microassur.php'); 
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_rs = "-1";
if (isset($_GET['Identifiant_direction'])) {
  $colname_rs = $_GET['Identifiant_direction'];
}
mysql_select_db($database_microassur, $microassur);
$query_rs = sprintf("SELECT * FROM region WHERE Identifiant_direction = %s", GetSQLValueString($colname_rs, "int"));
$rs = mysql_query($query_rs, $microassur) or die(mysql_error());
$row_rs = mysql_fetch_assoc($rs);
$totalRows_rs = mysql_num_rows($rs);
if($totalRows_rs==0){

if ((isset($_GET['Identifiant_direction'])) && ($_GET['Identifiant_direction'] != "") ) {
  $deleteSQL = sprintf("DELETE FROM direction WHERE Identifiant_direction=%s",
                       GetSQLValueString($_GET['Identifiant_direction'], "int"));

  mysql_select_db($database_microassur, $microassur);
  mysql_query("START TRANSACTION");
  $Result1 = mysql_query($deleteSQL, $microassur) or die(mysql_error());
if($Result1){ mysql_query("commit");header("Location: moddirection.php?suppdirection=success");}

else { mysql_query("rollback");
header("Location: moddirection.php?suppdirection=err&Identifiant_direction=".$colname_rs);
}


  
}
}
else
{
  header("Location: moddirection.php?suppdirection=existregion&Identifiant_direction=".$colname_rs);

}
mysql_free_result($rs);

?>